'''
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

#! /usr/bin/env python
# -*- coding: utf-8 -*-
#

import sys
from PyQt4.QtGui import *

def create_button(window, text, tool_tip, func, x, y, w, h):
	btn = QPushButton(text, window)
	btn.setToolTip(tool_tip)
	btn.clicked.connect(func)
	btn.move(x, y)
	btn.resize(w, h)
	return btn

def set_clipboard_fun_factory(sym):
	def f():
		QApplication.clipboard().setText(sym)
	return f

APL_Symbols = ['¯', '×', '÷', '∘',
 '∣', '∼', '≠', '≤', '≥', '≬', '⌶',
 '⋆', '⌾', '⍟', '⌽', '⍉', '⍝', '⍦',
 '⍧', '⍪', '⍫', '⍬','⍭', '←', '↑',
 '→', '↓', '∆', '∇', '∧', '∨', '∩',
 '∪', '⌈', '⌊', '⊤', '⊥', '⊂', '⊃',
 '⌿', '⍀', '⍅', '⍆', '⍏', '⍖', '⍊',
 '⍑', '⍋', '⍒', '⍎', '⍕', '⍱', '⍲',
 '○', '⍳', '⍴', '⍵', '⍺', '⍶', '⍷',
 '⍸', '⍹', '⍘', '⍙', '⍚', '⍛', '⍜',
 '⍮', '¨', '⍡', '⍢', '⍣', '⍤', '⍥',
 '⍨', '⍩', '⎕', '⍞', '⍠', '⍯', '⍰',
 '⍌', '⍍', '⍐', '⍓', '⍔', '⍗', '⌷',
 '⌸', '⌹', '⌺', '⌻', '⌼', '⍁', '⍂',
 '⍃', '⍄', '⍇', '⍈' ]

app = QApplication(sys.argv)

win_height = 832
win_width = 512
win = QWidget()
win.resize(win_height, win_width)
win.setWindowTitle("APL keyboard")

font = QFont(u'Times', 32, QFont.Bold, True)

buttons = []
x_pos = 0
y_pos = 0

for index, sym in enumerate(APL_Symbols):
	if x_pos >= win_height:
		x_pos = 0
		y_pos += 64
	buttons.append
	(create_button(win, sym, 'Copy to clipboard',
	set_clipboard_fun_factory(sym),
	x_pos, y_pos, 64, 64).setFont(font))
	x_pos += 64

win.show()
 
sys.exit(app.exec_())
